package com.xiaoge.work.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiaoge.response.Result;
import com.xiaoge.system.entity.User;
import com.xiaoge.system.vo.UserVo;
import com.xiaoge.work.Vo.S3Vo;
import com.xiaoge.work.entity.SThird;
import com.xiaoge.work.service.SThirdService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaoge
 * @since 2021-04-04
 */
@CrossOrigin
@RestController
@RequestMapping("/sThird")
public class SThirdController {
    @Autowired
    private SThirdService sThirdService;

    @ApiOperation(value = "")
    @PostMapping("/findList")
    public Result findList(@RequestBody S3Vo s3Vo) {
        QueryWrapper<SThird>queryWrapper=getWrapper(s3Vo);
        List<SThird> sThirds=sThirdService.list(queryWrapper);
        return Result.ok().data("records",sThirds);
    }

    private QueryWrapper<SThird> getWrapper(S3Vo s3Vo) {
        QueryWrapper<SThird> queryWrapper = new QueryWrapper<>();
        if (s3Vo != null) {

            //查询每个条件
            if (!ObjectUtils.isEmpty(s3Vo.getName())) {
                queryWrapper.like("name", s3Vo.getName());
            }
            if (!ObjectUtils.isEmpty(s3Vo.getNum())) {
                queryWrapper.eq("num", s3Vo.getNum());
            }
            if (!ObjectUtils.isEmpty(s3Vo.getSupplerId())) {
                queryWrapper.eq("supplier_id", s3Vo.getSupplerId());
            }
            if (!ObjectUtils.isEmpty(s3Vo.getPrice())) {
                queryWrapper.ge("price", s3Vo.getPrice());
            }
            if (!ObjectUtils.isEmpty(s3Vo.getPrice1())) {
                queryWrapper.le("price", s3Vo.getPrice1());
            }

        }
        return queryWrapper;
    }
}
